home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9998 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] namespace #1
  5. Date: Tue, 05 Mar 1996 15:57:49 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4hho8l$aec@news.halcyon.com>
  8. References: <4hf81b$aov@crl.crl.com>
  9. NNTP-Posting-Host: blv-pm3-ip8.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. dbridges@crl.com (Dick Bridges) wrote:
  13.  
  14. >#include <iostream.h>
  15.  
  16. >namespace foo
  17. >{
  18. >    int Value = 43;
  19. >};
  20.  
  21. >void main()
  22. >{
  23. >    int Value = 65;
  24. >    using namespace foo;
  25. >    cout << Value << endl;
  26. >}
  27.  
  28. >// QUESTIONS:
  29. >// 1) Is this a valid program
  30. >// 2) If so what is the expected output, if not what is the error
  31. >// 3) What would be the result of using a using declaration instead
  32. >//    instead of a using directive
  33. >//
  34. >// NOTES:
  35. >// 1) The Microsoft VC++ 4.0 compiler complains that Value is an
  36. >//    ambiguous symbol. Is this correct?
  37.  
  38. You can't replace namespaces with "using," you can ony add additional
  39. namespaces.  Main defined Value, foo defined Value, and your using the
  40. namespace of both in the cout <<... statement.  
  41.  
  42. I've had similar problems in a program mixing third-party and
  43. home-grown components: two headers defined classes with the same name
  44. and I had to include both in one module.  Namespaces did not allow me
  45. to switch which implementation CXxxx really meant.
  46.  
  47.                     --Norm
  48.  
  49.